package mosync.mobilelualiveditor.ui;

public class WidgetPropertyInstance
{
	public WidgetPropertyInstance(WidgetPropertyType type, WidgetInstance widget)
	{
		this.mType = type;
		this.mWidget = widget;
		this.mValue = type.mDefaultValue;
	}

	public String getValue()
	{
		return mValue;
	}

	public void setValue(String value)
	{
		this.mValue = value;
	}

	public WidgetPropertyType getType()
	{
		return mType;
	}

	String quote(String s)
	{
		return "\"" + s + "\"";
	}

	private String makeTabs(int n)
	{
		String ret = "";
		for (int i = 0; i < n; i++)
			ret += "\t";
		return ret;
	}

	public String toXML(int numTabs)
	{
		return makeTabs(numTabs) + "<Property name=\"" + mType.mName
			+ "\" value=\"" + mValue + "\"/>\n";
	}

	public String toCpp()
	{
		return "\t\tmaWidgetSetProperty(" + mWidget.getName() + ", "
			+ quote(mType.mName) + ", " + quote(mValue) + ");\n";
	}

	public String toLua()
	{
		if (mType.equals("resource"))
		{
			return "maWidgetSetProperty(" + mWidget.getName() + ", "
				+ quote(mType.mName) + ", " + mValue + ")\n";
		}
		else
		{
			return "maWidgetSetProperty(" + mWidget.getName() + ", "
				+ quote(mType.mName) + ", " + quote(mValue) + ")\n";
		}
	}

	public WidgetInstance getWidgetInstance()
	{
		return mWidget;
	}

	private String mValue;
	private WidgetPropertyType mType;
	WidgetInstance mWidget;
}